﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.ServiceModel;
using Pub.Lib;
using WCFContracts;
using System.ServiceModel.Description;
using WCFGzip;
using System.ServiceModel.Channels;
using System.Configuration;
using System.ServiceModel.Configuration;
using System.ServiceModel.Security;
using System.Net;
using Pub;
using Pub.Tools;


namespace WCFSerApp
{
    public partial class WCFSerAppForm : Form
    {
        public WCFSerAppForm()
        {
            InitializeComponent();
        }

        ServiceHost host = new ServiceHost(typeof(WCFAccess));
        string ServerPort = string.Empty;
        string ListenPort = string.Empty;

        private void WCFSerAppForm_Load(object sender, EventArgs e)
        {
            try
            {
                PubVar.Domain = Helper.DBHelper.GetInf("domain", PubVar.ConnMain, DataAccessType.CS).Trim();
            }
            catch (Exception ex)
            {
                SysTools.WriteTxt(PubVar.LogFile, "读取domain出错:" + ex.Message.ToString());
            }
            ServerPort = XmlTools.Read(PubVar.SysSetXml, "SysSet/ServerPort");
            PubVar.GetSYSDAT();
            string _UpdateSQL = XmlTools.Read(PubVar.SysSetXml, "SysSet/UpdateSQL");

            PubVar.SysUpdateSQL = SysTools.ToBoolean(_UpdateSQL);


            ListenPort = (SysTools.ToInt(ServerPort) + 1).ToString();

        }

        private void btnBasic_Click(object sender, EventArgs e)
        {
            string strMess = Pub.Lib.WCFServer.Basic(ref host, ServerPort, ListenPort);
            labPort.Text = strMess;
            MessageBox.Show(strMess);
        }

        private void btnZip_Click(object sender, EventArgs e)
        {
            string strMess = Pub.Lib.WCFServer.ZipCustom(ref host, ServerPort, ListenPort);
            labPort.Text = strMess;
            MessageBox.Show(strMess);
        }


        private void btnClose_Click(object sender, EventArgs e)
        {
            string strMess = string.Empty;
            try
            {
                host.Close();                
                strMess = "WCF服务关闭成功";
            }
            catch (Exception ex)
            {
                strMess = "WCF服务关闭失败！\r\n" + ex.Message.ToString();
            }
            labPort.Text = strMess;
            MessageBox.Show(strMess);
        }


    }
}
